#!/bin/bash
# shellcheck source=meta-google/recipes-google/networking/gbmc-net-common/gbmc-net-lib.sh
source /usr/share/gbmc-net-lib.sh || exit

# shellcheck disable=SC2043
for nic in @IFS@; do
  netconfdir="/etc/systemd/network/-bmc-${nic}.network.d"
  nftconfdir="/etc/nftables/"
  mkdir -p "${netconfdir}"
  mkdir -p "${nftconfdir}"
  read -r -d '' nfcontents <<EOF
table inet filter {
  chain gbmc_br_pub_input {
    udp dport 546 accept
    udp dport 547 accept
  }
}
EOF
  printf "%s" "$nfcontents" > "${nftconfdir}/50-gbmc-$nic-lab.rules"
  echo "[Network]" > "${netconfdir}/10-ra-config.conf"
  echo "IPv6AcceptRA=true" >> "${netconfdir}/10-ra-config.conf"
  systemctl reload nftables
  gbmc_net_networkd_reload "${nic}"
done

